common={
	initCatalogueMagePage:function(){
		this.Authorization= window.localStorage.getItem("auth_token") || '';
		// 绑定dom对象
		this.obj = {
			searchText:$('#searchText'),
		};
		// 声明全局变量
		this.vars = {
			datatable:[],
			searchTable:{
				owersName:"",
				driverName:"",
				idCard:"",
				licence:"",
				page:1,
				size:10,
			},
		};
		this.diquSelceted();
		this.ajaxtable();
		this.btnEvent();

	},
	diquSelceted:function(){
		var self=this;
		var mapurl=HTTP+urls.diquSelceted;
		console.log(mapurl)
		$.ajax({
			headers: {
				authorization: self.Authorization
			},
			contentType: "application/json;charset=utf-8",
			dataType: "json",
			url: mapurl,
			type: "get",
			success: function (data) {
				console.log(data);
				data[0].code=1;
				$.each(data[0].cityAreaVOS,function(i,dom){
					data[0].cityAreaVOS[i].code=2;
					$.each(data[0].cityAreaVOS[i].cityAreaVOS,function(j,dom){
						data[0].cityAreaVOS[i].cityAreaVOS[j].code=3;
					})
				})
				self.creatMainRido("qrm-main",data,"cityAreaVOS","code");
			}
		});

	},
	tableEvent:function(id,data,columns,paginationShow,total){
		var self=this;
		$('#' + id).bootstrapTable({
			method: 'get',
			cache: false,
			height: 430,
			pagination: paginationShow,
			pageSize: self.vars.searchTable.size,
			pageNumber:self.vars.searchTable.page,
			showColumns: true,
			striped: true,
			columns: columns,
			data :data,
			sidePagination: 'server',
			totalRows: total,
			onPageChange: function (size, number) {
				console.log(size)
				console.log(number)
				self.vars.searchTable.size=size;
				self.vars.searchTable.page=number;
				self.ajaxtable()
			},
			formatNoMatches: function(){
				return '无符合条件的记录';
			}
		});
	},
	creatMainRido:function(id,attr,child,jibie){
		$(id).html("");
		var sttrdiv="";
		for(var i=0;i<3;i++){
			sttrdiv +="<div class='qrm-border"+(i+1)+"' style='display:none'>"+
				"<ul class='qrm-lev-"+(i+1)+" qrm-lev' id='qrm-border1'>"+
				"</ul>"+
				"</div>"
		};
		$(".qrm-main").html(sttrdiv);
		var str="";
		$("#qrm-border1").html("");
		var forTree = function(o){
			for(var i=0;i<o.length;i++){
				var urlstr = "";
				try{
					urlstr = "<li><span data-id='"+o[i]["id"]+"'>"+ o[i]["name"] +"</span><i class='qrm-arrow-right'></i><ul class='li-zi-"+o[i][jibie]+"' style='display: none'>";
					str += urlstr;
					if(o[i][child] != null){
						forTree(o[i][child]);
					}
					str += "</ul>";
				}catch(e){}
			}
			return str;
		};
		$("#qrm-border1").html(forTree(attr));
	},
	ajaxtable:function(){
		var self=this;
		jrequest.get(urls.driver,self.vars.searchTable).then(res => {
			console.log("123",res)
			self.vars.datatable = res.data;
			$('#check_detail').bootstrapTable('destroy');
			self.creatTable(res)
		})
	},
	creatTable:function(res){
		var self=this;
		var columnsOne = [
			{
				field: 'id',
				title: '序号',
				align: 'center',
				formatter: function (value, row, index) {
					var pageSize=self.vars.searchTable.size;
					var pageNumber=self.vars.searchTable.page;
					return pageSize * (pageNumber - 1) + index + 1;
				}
			},
			{
				field: 'driverName',
				title: '驾驶员姓名',
			},
			{
				field: 'mobile',
				title: '电话',
			},
			{
				field: 'drivingLicense',
				title: '驾驶员证号',
			},
			{
				field: 'idCard',
				title: 'idCard',
			},
			{
				field: 'platformName',
				title: '平台',
			},
			{
				field: 'owersName',
				title: '企业',
			},
			{
				field: 'licence',
				title: '从业资格证号',
			},
			{
				field: 'orgName',
				title: '发证机构',
			}
		];
		self.tableEvent("check_detail",res.data,columnsOne,true,res.total);
	},
	btnEvent:function(){
		var self=this;
		$(".search-div .j-search-btn button").eq(0).unbind("click");
		$(".search-div .j-search-btn button").eq(0).click(function(){
			self.vars.searchTable.owersName=$(".j-search-row .item").eq(0).find("input").val();
			self.vars.searchTable.driverName=$(".j-search-row .item").eq(1).find("input").val();
			self.vars.searchTable.idCard=$(".j-search-row .item").eq(2).find("input").val();
			self.vars.searchTable.licence=$(".j-search-row .item").eq(3).find("input").val();
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable()
		});
		$(".search-div .j-search-btn button").eq(1).unbind("click");
		$(".search-div .j-search-btn button").eq(1).click(function(){
			$(".j-search-row .item").eq(0).find("input").val("");
			$(".j-search-row .item").eq(0).find("input").attr("data-id","")
			$(".j-search-row .item").eq(1).find("input").val("");
			$(".j-search-row .item").eq(2).find("input").val("");
			$(".j-search-row .item").eq(3).find("input").val("");
			self.vars.searchTable.owersName="";
			self.vars.searchTable.driverName="";
			self.vars.searchTable.idCard="";
			self.vars.searchTable.licence="";
			self.vars.searchTable.page=1;
			self.vars.searchTable.size=10;
			self.ajaxtable()
		})
	},

}

$(function(){
	common.initCatalogueMagePage();
});
